<?php
if (!(defined('IN_IA'))) 
{
    exit('Access Denied');
}

//门店模型类
class Store_MxShopModel
{

    //常用变量
    private $storeTable;

    //构造基本信息
    public function __construct()
    {
        $this->storeTable = tablename('mx_shop_mendian');
    }

    /*
     * 输入门店id获取门店信息
     * @param int $id 门店id
     * @param array $select 查询的字段
     * @return array/null
     * */
    public function getStoreById($id, $select)
    {
        global $_W,$_GPC;

        if(empty($id))
        {
            return null;
        }

        $condition = 'id=:id AND uniacid=:uniacid AND status=1 AND deleted=0';
        $params = array(
            ':id' => $id,
            ':uniacid' => $_W['uniacid'],
        );

        $info = '*';
        if(!empty($select) && is_array($select))
        {
            $info = array('id');
            foreach ($select as $item)
            {
                if(is_string($item)){
                    $info[] = $item;
                }
            }
            $info = implode(',', $info);
        }

        return pdo_fetch('SELECT '.$info.' FROM '.$this->storeTable);
    }

    /*
     * 输入门店编号获取门店信息
     * @param string 门店number
     * @param array $select 查询的字段
     * @return array/null
     * */
    public function getStoreByNumber($number, $select)
    {
        global $_W,$_GPC;

        if(empty($number))
        {
            return null;
        }

        $condition = 'mdnumber=:mdnumber AND uniacid=:uniacid AND status=1 AND deleted=0';
        $params = array(
            ':mdnumber' => $number,
            ':uniacid' => $_W['uniacid'],
        );

        $info = '*';
        if(!empty($select) && is_array($select))
        {
            $info = array('id');
            foreach ($select as $item)
            {
                if(is_string($item)){
                    $info[] = $item;
                }
            }
            $info = implode(',', $info);
        }

        return pdo_fetch('SELECT '.$info.' FROM '.$this->storeTable);
    }

}
